package com.dfbz.bigdata.modules.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dfbz.bigdata.common.utils.R;
import com.dfbz.bigdata.modules.system.doman.UserBrand;

import com.dfbz.bigdata.modules.system.service.UserBrandService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;


/**
 * @Auther:东方标准
 * @Date:2022/9/26-09-26-16:20
 * @Decsription:com.dfbz.bigdata.modules.system.controller
 * @Version:1.0
 */
@RestController
@RequestMapping("/buser")
@Slf4j
public class UserBrandController {
    @Autowired
    private UserBrandService userBrandService;

    @GetMapping("/{id}")
    public R<UserBrand> getByIdUserandd(@PathVariable Long id){
        System.out.println("!!!1111111111111111111111111111111111111111111111111111111111");
        UserBrand userBrand = userBrandService.getById(id);
        System.out.println(userBrand);
        return R.success(userBrand);
    }

    @GetMapping
    public R<Page> getuser(String username,Long currentPage,Long pagesizes){
        System.out.println("UserBrandController.getuser");

        LambdaQueryWrapper<UserBrand> lqw=new LambdaQueryWrapper<>();
        lqw.like(!username.isEmpty(),UserBrand::getBrandsName,username);
        Page page =new Page(currentPage,pagesizes);

        userBrandService.page(page,lqw);
        return R.success(page);
    }

    @DeleteMapping("/{id}")
    public R<String> delete(@PathVariable Long id){
        boolean b = userBrandService.removeById(id);
        if (b){
            return R.success("删除成功");
        }
        else return  R.error("系统繁忙");

    }

    @PostMapping("auth")
    public R<String> insertBrand(@RequestBody UserBrand userBrand){
        log.info("brand----------{}",userBrand);
        userBrand.setBrandsLabel("一星级");
        userBrand.setCreateTime(new Date());
        userBrand.setUpdateTime(new Date());

        boolean b = userBrandService.save(userBrand);
        if (b){
            return R.success("认证成功");
        }
        else return  R.error("系统繁忙");
//        return R.success("test");
    }
}
